<?php

class MemberStatsController extends BaseController
{
	
	public function actionAdmin()
	{
		$model = new Member();
		$model->unsetAttributes();
		//审核通过
		$model->zm_status = 2;
		//销费额倒序
		$model->list_order = 2;
		
		if(isset($_GET['Member']))
			$model->attributes = $_GET['Member'];
	
		
		$this->render('admin',array(
				'model'=>$model,
		));
	}
	
	//数据导出
	public function actionExport(){
		$model = new Member();
		$model->unsetAttributes();
		if(isset($_GET['Member']))
			$model->attributes = $_GET['Member'];
	
		$criteria=new CDbCriteria;
		$criteria->compare('zm_name',$model->zm_name,true);
		$criteria->compare('zm_status',2);
		//销费额倒序
		$criteria->join = " LEFT JOIN {{order}} o ON o.zm_id=t.zm_id";
		$criteria->select =  " t.*,SUM( o.zo_amount) as nums ";
		$criteria->group =  " t.zm_id ";
		$criteria->order = " nums DESC ";
		
		$members = Member::model()->findAll($criteria);
 		$this->toExcel($members,array('zm_id','zm_name','zm_email','zm_mob','zm_value','inputtime:datetime','buyamount'),'会员销费排行榜');
		exit;
	}
	
	
	public function behaviors()
	{
		return array(
				'eexcelview'=>array(
						'class'=>'ext.eexcelview.EExcelBehavior',
				),
		);
	}

	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}